/**
 * Copyright &copy; com.nmf
 */
package com.nmf.site.biz.bill.service;

import java.util.List;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nmf.site.common.PageDb;
import org.apache.commons.lang3.StringUtils;

import com.nmf.dao.gen.bean.BizProjectBill;
import com.nmf.dao.gen.bean.BizProjectBillExample;
import com.nmf.dao.gen.BizProjectBillMapper;
import com.nmf.site.common.enums.DelFlagEnums;
import com.nmf.site.common.persistence.Page;
import com.nmf.site.common.utils.IdGenerater;

/**
 * 工程单据Service
 * @author 北冥
 * @version 2019-01-09
 */
@Service
@Transactional(readOnly = true)
public class BizProjectBillService{

	@Autowired
	BizProjectBillMapper bizProjectBillMapper;
	@Autowired
	IdGenerater idGenerater;
	
	public BizProjectBill get(String no) {
		return bizProjectBillMapper.selectByPrimaryKey(no);
	}
	
	public List<BizProjectBill> findList(BizProjectBill bizProjectBill) {
		BizProjectBillExample bizProjectBillExample = new BizProjectBillExample();
		BizProjectBillExample.Criteria criteria = bizProjectBillExample.createCriteria();
		
		return bizProjectBillMapper.selectByExample(bizProjectBillExample);
	}
	
	public Page<BizProjectBill> findPage(Page<BizProjectBill> page, BizProjectBill bizProjectBill) {
		BizProjectBillExample bizProjectBillExample = new BizProjectBillExample();
		BizProjectBillExample.Criteria criteria = bizProjectBillExample.createCriteria();
		
		bizProjectBillExample.setPage(page);
		
		List<BizProjectBill> dlist = bizProjectBillMapper.selectByExample(bizProjectBillExample);
		page.setList(dlist);
		page.setCount(bizProjectBillMapper.countByExample(bizProjectBillExample));
		
		return page;
	}
	
	@Transactional(readOnly = false)
	public void save(BizProjectBill bizProjectBill) {
		if(StringUtils.isNotEmpty(bizProjectBill.getId())&&get(bizProjectBill.getId())!=null) {
			bizProjectBillMapper.updateByPrimaryKeySelective(bizProjectBill);
		}else {
			Date date = new Date();
			bizProjectBill.setCreateDate(date);
			bizProjectBill.setId(idGenerater.genClsNo("bizProjectBill"));
			bizProjectBill.setUpdateDate(date);
			bizProjectBillMapper.insertSelective(bizProjectBill);
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(BizProjectBill bizProjectBill) {
		bizProjectBillMapper.deleteByPrimaryKey(bizProjectBill.getId());
	}
	
}